package com.abc.webfirst;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/regist")
public class RegistServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        //1.获取客户的请求
        String username = request.getParameter("username");
        String password = request.getParameter("pwd");
        String gender = request.getParameter("gender");
        String home = request.getParameter("home");
        String[] hobbies = request.getParameterValues("hobby");

        //2.处理请求，完成业务逻辑(调用相应方法）
        System.out.println(username);
        System.out.println(password);
        System.out.println(gender);
        System.out.println(home);
        for (String hobby : hobbies) {
            System.out.println(hobby);
        }

        //3.做出响应
        response.setContentType("text/html;charset=UTF-8");

//        PrintWriter out = response.getWriter();
//
//        out.print("<html><body>");
//        out.print(username + " regist success!");
//        out.print("</body></html>");
//
//        out.flush();//清空缓存
//        out.close();

        //请求转发
       // request.getRequestDispatcher("login.jsp").forward(request, response);
        //请求重定向
        response.sendRedirect("login.jsp");
    }
}
